<template>
  <div class="admin-container">
    <!-- <div class="container-1200"> -->
      <div class="title mg-B20">新增项目月报表</div>
      <el-form
        :model="projectExecuteForm"
        :rules="projectExecuteRules"
        ref="projectExecuteForm"
        label-width="100px"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectName">
              <el-input v-model="projectExecuteForm.projectName"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="已投资" prop="ytz">
              <el-input v-model="projectExecuteForm.ytz"> </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="已创收" prop="ycs">
              <el-input v-model="projectExecuteForm.ycs" type="number">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="已创就业人数" prop="ycjyrs">
              <el-input v-model="projectExecuteForm.ycjyrs"> </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="新增人才数" prop="xzrcs">
              <el-input v-model="projectExecuteForm.xzrcs" type="number">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="新增专利" prop="xzzl">
              <el-input v-model="projectExecuteForm.xzzl"> </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="新获得荣誉数" prop="xhdrys">
              <el-input v-model="projectExecuteForm.xhdrys" type="number">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item
              label="政策兑现融资额"
              prop="zcdxlz"
              label-width="120px"
            >
              <el-input v-model="projectExecuteForm.zcdxlz"> </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item
              label="上报时间"
              prop="createDate"
              label-width="120px"
            >
              <el-input v-model="projectExecuteForm.createDate" disabled> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="相关资料" prop="meta">
              <single-upload
                listType="picture-card"
                v-model="projectExecuteForm.meta"
              ></single-upload>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item>
          <el-button type="primary" @click="onSubmit('projectExecuteForm')"
            >立即更新</el-button
          >
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    <!-- </div> -->
  </div>
</template>

<script>
import SingleUpload from "@/components/Upload/singleUpload";
import { find as companyFind } from "@/api/company";
import { list as dictList } from "@/api/dict";
import utils from "@/utils/utils.js";
import { validPhone, validPositiveIntAndZero } from "@/utils/validate.js";
import { save as projectSave, find as projectFind } from "@/api/project";
import { update as projectExecuteUpdate, find as projectExecuteFind } from "@/api/projectExecute";

export default {
  components: { SingleUpload },
  name: "project",
  data() {

    const validateCapital = (rule, value, callback) => {
      if (utils.isNull(value)) {
        callback();
      } else if (!validPositiveIntAndZero(value)) {
        callback(new Error("必须为大于等于0的数值"));
      } else {
        callback();
      }
    };

    return {
      projectExecuteForm: {
        projectId:"",
        projectName: "", //项目名称',
        ytz: "", //已投资',
        ycs: "", //已创收',
        ycjyrs: "", //已创就业人数',
        xzrcs: "", //新增人才数',
        xzzl: "", //新增专利',
        xhdrys: "", //新获得荣誉数',
        zcdxlz: "", //政策兑现融资额',
        meta: "", //相关资料[{name:,url:}]'
        companyId: "",
        createDate:""
      },
      projectExecuteRules: {
        projectName: [
          { required: true, message: "请输入项目名称", trigger: "blur" },
        ],
        ytz: [{  validator: validateCapital, trigger: "blur" }],
        ycs: [{  validator: validateCapital, trigger: "blur" }],
        ycjyrs: [{  validator: validateCapital, trigger: "blur" }],
        xzrcs: [{  validator: validateCapital, trigger: "blur" }],
        xzzl: [{  validator: validateCapital, trigger: "blur" }],
        xhdrys: [{  validator: validateCapital, trigger: "blur" }],
        zcdxlz: [{  validator: validateCapital, trigger: "blur" }],
      },

      companyId: "",
      companyInfo: {},
    };
  },
  watch: {
    $route: {
      handler: function (route) {},
      immediate: true,
    },
  },

  created() {
    if (this.$route.query) {
      this.projectExecuteForm.companyId = this.companyId = this.$route.query.companyId;
      this.projectExecuteForm.projectId = this.projectId = this.$route.query.projectId;
      this.projectExecuteId = this.$route.query.projectExecuteId;
      this.projectFind(this.projectId);
      this.projectExecuteFind(this.projectExecuteId)
    }
  },

  mounted() {},

  destroyed() {},

  methods: {
    //获取月报信息
    projectExecuteFind(id) {
      projectExecuteFind(id).then((res) => {
        console.log("获取月报信息--", res);
        if (res.type == "success") {
          this.projectExecuteForm = res.data.projectExecute;
          this.projectExecuteForm.createDate = utils.dateFormatter(this.projectExecuteForm.createDate)
        }
      });
    },

    //获取项目信息
    projectFind(id){
      projectFind(id).then((res) => {
        console.log("获取项目信息--", res);
        if (res.type == "success") {
          this.projectInfo = res.data.project;
          this.projectExecuteForm.projectName = res.data.project.projectName
        }
      });
    },

    //表单提交事件
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          projectExecuteUpdate(this.projectExecuteForm)
            .then((res) => {
              console.log("projectExecuteUpdate--", res);
              if (res.type == "success") {
                this.$message.success("更新月报成功");
                this.$router.push({
                  path: "/projectExecute/list",
                  query: { companyId: this.companyId,projectId:this.projectId },
                });
              }
            })
            .catch((err) => {
              this.$message.error(err.msg);
            });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
